package com.huatai.exchange.utils;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.faneui.dal.DBUtils;
import com.faneui.service.Dbconfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

@Component
public class TaUtils {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public String checkTwoDataIsFinish() throws BusinessException {
        logger.info("校验估值表是否生成");
        Connection conn = null;
        String user = "ta4_query";
        String r = null;
        try {
            conn = DBUtils.getConnection(Dbconfig.TA4DB, user, Dbconfig.getPasswordByUserId(user));
            String sql = "  select 1 " +
                    "  from (select to_char(count(distinct t.c_status)) statuscount\n" +
                    "          from htta4.tdealflag t) x,\n" +
                    "       (select t.c_dealflag flag from htta4.ttaflowlog t where t.l_id = '50') y\n" +
                    "    where x.statuscount = 1 and y.flag = 1";
            List<Map<String, Object>> result = DBUtils.executeQuery(conn, sql );
            r = ListUtils.isEmpty(result) ? "TA第二次数据未准备好" : "1";
        } catch (Exception ex) {
            logger.error("", ex);
            r = ex.getMessage();
        } finally {
            DBUtils.closeAll(conn);
        }
        logger.info("校验估值表是否生成");
        return r;
    }


}
